package com.hfh.homework;

import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.*;

/**
 * @Author hfh
 * @Date 2022 09 07 14 20
 **/
public class Work6 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        Set<Student> set = new TreeSet<>();
        String[] arr;
        Student student;

        System.out.println("请按照‘学号#姓名#年龄’的格式输入信息");
        String str = scan.nextLine();
        while(!str.equals("exit")){
            arr = str.split("#");
            student = new Student(arr[0],arr[1],arr[2]);
            set.add(student);
            str = scan.nextLine();
        }
        try(Writer writer = new FileWriter("D:\\JavaProject\\newlearn\\day22\\file\\a.txt",true)) {
            for (Student s : set){

                String strings = s.getId()+"#"+s.getName()+"#"+s.getAge();
                char[] chars = strings.toCharArray();
                writer.write(chars);
                writer.write("\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
